<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
       <!-- 引入Vue 全局注册一个名为Vue的构造函数 -->
       <script src="./js/vue.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="app">
        <button @click="add()">添加一个值</button>
     <!-- 遍历 -->

     <!-- key值会复用一样的虚拟dom, -->
     <!-- 用index作为key,打乱前面顺序会导致出错 。没有写key值，vue会自动用index作为key值-->
     <!-- 最好使用每条数据的唯一标识作为key值 -->
     <ul>
        <li v-for="(person,index) in persons" :key="index">{{person.name}},{{person.age}}
            <input type="text">
        </li>
     </ul>
    </div>

    <script>
   var app=new Vue({
    el:"#app",
    data:{
        persons:[
            {id:'001',name:'张三',age:18},
            {id:'002',name:'张三',age:19},
            {id:'003',name:'张三',age:20}
        ]
    },
    methods:{
        add(){
            this.persons.unshift({id:"004","name":"张三",age:18})
        }
    }
   })
    </script>
</body>
</html>